package com.awonsome.common.core.result;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import javax.xml.transform.Result;
import java.io.Serializable;

/**
 * @author yangdejun
 * @date 2022/1/18 10:30
 */
@AllArgsConstructor
@NoArgsConstructor
public enum ResultCode implements IResultCode, Serializable {
    SUCCESS("00000", "OK"),
    SYSTEM_EXECUTION_ERROR("00001", "系统执行出错"),
    DEGRADATION("B0220", "系统功能降级"),
    USER_NOT_EXIST("A0201", "用户不存在"),
    USERNAME_OR_PASSWORD_ERROR("A0210", "用户名或密码错误")
    ;

    private String code;

    private String msg;

    /**
     * 根据状态码获取对应的信息
     * @param code
     * @return
     */
    public static ResultCode getValue(String code) {
        for (ResultCode value : values()) {
            if (values().getClass().equals(code)) {
                return value;
            }
        }
        return SYSTEM_EXECUTION_ERROR;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    @Override
    public String toString() {
        return "ResultCode{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                '}';
    }
}
